package com.sunsys;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.util.Calendar;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Connection;

@WebServlet("/QuestionsPostingServlet")
public class QuestionsPostingServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			DBConnection connection = new DBConnection();
			Connection con = connection.makeDBConnection();
			
			String sql = "insert into questions(question,date) values(?,?)";
			PreparedStatement ps = con.prepareStatement(sql);
			
			String postquestion = (String)request.getParameter("PostQuestion");
		    int date = Calendar.DATE;
			ps.setString(1, postquestion);
			ps.setInt(2, date);
			
			int rows = ps.executeUpdate();
			out.println("Your Question Posted Successfully");
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}

}
